#include "erroritem.h"
#include <QPainter>
#include "global/globalvar.h"
#include "global/myresource.h"

ErrorItem::ErrorItem()
{
}

void ErrorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->save();

    if(globalvar::m_logic.m_ierrorNum < 4)
    {
        for(int i = 0; i < globalvar::m_logic.m_ierrorNum;++i)
        {
            painter->drawImage(QRectF(i * 40.0f,0.0f,40.0f,40.0f),
                               *MyResource::m_gameErrorImage);
        }
    }
    else
    {
        painter->drawText(QRectF(0.0f,0.0f,120.0f,40.0f),
                          Qt::AlignCenter,
                          QString("%1 %2").arg(globalvar::m_logic.m_ierrorNum)
                          .arg(tr("This failure")));
    }

    painter->restore();
}

QRectF ErrorItem::boundingRect() const
{
    return QRectF(0.0f,0.0f,120.0f,40.0f);
}
